package com.ruoyi.common.enums.wecom;

import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum WecomChatGroupMemQuitSceneEnum {


    SELF_QUIT(0, "自己退群"),
    REMOVED(1, "群主/群管理员移出");

    private final Integer code;
    private final String desc;

    private static final Map<Integer, WecomChatGroupMemQuitSceneEnum> ENUM_MAP;

    static {
        WecomChatGroupMemQuitSceneEnum[] values = values();
        Map<Integer, WecomChatGroupMemQuitSceneEnum> enToCn = new HashMap<>(values.length);
        for (WecomChatGroupMemQuitSceneEnum value : values) {
            enToCn.put(value.getCode(), value);
        }
        ENUM_MAP = Collections.unmodifiableMap(enToCn);
    }

    /**
     * 根据类型查找枚举
     */
    public static WecomChatGroupMemQuitSceneEnum getEnumByType(Integer type) {
        WecomChatGroupMemQuitSceneEnum wecomChatGroupMemQuitSceneEnum = ENUM_MAP.get(type);
        if (ObjectUtil.isEmpty(wecomChatGroupMemQuitSceneEnum)) {
            throw new RuntimeException("类型有误");
        }
        return wecomChatGroupMemQuitSceneEnum;
    }

}
